home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // OTIMER.H
- //
- // Timer class... using Object callback
- //
- //--------------------------------------------------------------------------
-
- #include "otimer.h"
- #include "objcallb.h"
-
-
- //--------------------------------------------------------------------------
- //
- // OTimer :: CONSTRUCTOR
- //
- //--------------------------------------------------------------------------
- OTimer::OTimer() : wIDTimer(NULL)
- {
- instTimer = MakeObjectThunk((FARPROC) TimerCallback, this);
- }
-
-
- //--------------------------------------------------------------------------
- //
- // OTimer :: DESTRUCTOR
- //
- //--------------------------------------------------------------------------
- OTimer::~OTimer()
- {
- stop(); // always stop the timer!
- FreeObjectThunk(instTimer);
- }
-
-
- //--------------------------------------------------------------------------
- //
- // OTimer :: TimerCallback - The actual static callback
- //
- //--------------------------------------------------------------------------
- CALLBACK OTimer::TimerCallback(HWND, UINT, UINT, DWORD dwTime)
- {
- // ES:BX set from the thunk
- OTimer *PThis = (OTimer *) MAKELP(_ES,_BX);
-
- PThis->timerHit(dwTime);
-
- return 0;
- }
-
-
- //--------------------------------------------------------------------------
- //
- // OTimer :: go
- //
- // starts or re-starts a timer
- //
- //--------------------------------------------------------------------------
- BOOL OTimer::go(UINT wMsec)
- {
- if(wIDTimer) stop();
-
- wIDTimer = SetTimer(NULL, 0, wMsec, (TIMERPROC) instTimer);
-
- return wIDTimer != NULL;
- }
-
-
- //--------------------------------------------------------------------------
- //
- // OTimer :: stop
- //
- // stops a timer
- //
- //--------------------------------------------------------------------------
- BOOL OTimer::stop()
- {
- if(wIDTimer && KillTimer(NULL, wIDTimer)) {
- wIDTimer = NULL;
- return TRUE;
- }
-
- return FALSE;
- }